handle duplicate events - #2
Open
rgoers wants to merge 9 commits into
Open
Conversation
Member
Honestly I am not a big fan of Flapdoodle. IIRC tests using Flapdoodle were flaky. Can we use a Docker image instead? |
ppkarwasz
force-pushed
the
handle-duplicates
branch
from
September 2, 2026 17:03
5e12f3a to
09d6432
Compare
# Conflicts: # flume-mongodb-sink/pom.xml
…en an error occurs
An ordered insertMany() stops at the first duplicate key, which forced a fallback that re-inserted the rest of the batch one document at a time. Mark the batch unordered instead: the server attempts every document and reports each rejected one, with its position in the batch, so a single round trip both writes everything insertable and yields the exact duplicate count. Log the skipped documents broken down by the unique index that rejected them, with the offending documents themselves at debug level. Drop the DuplicateKeyException handling: that exception is only thrown by the legacy com.mongodb.MongoClient.getDB API, which no longer exists in the 5.x driver, so the catch was unreachable. Assisted-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TeHbzgwRzHuwpUajMksuMD
ppkarwasz
approved these changes
Sep 11, 2026
ppkarwasz
left a comment
Member
There was a problem hiding this comment.
I changed the way documents are inserted: they are inserted using an unordered option, which allow the server to try inserting all the documents before failing. The number of duplicates is read from the thrown exception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flume provides guaranteed delivery of events. That means events will be delivered at least once. If an event gets delivered to multiple instances of the sink then the duplicates should fail on a duplicate key, provided the user has specified a key. In these cases we do not want the event being written to be treated as either a success or a failure.
Flapdoodle was also added for embedded MongoDB testing instead of relying on a fake writer.